	
	window.onresize=function(){
		var entryDiv = document.getElementById('entryDiv');
		var win_Width = document.body.clientWidth;
		entryDiv.style.width =win_Width-5;
	}	
	
	Ext.onReady(function() {	
		var entryDiv = document.getElementById('entryDiv');
		var win_Width = document.body.clientWidth;
		entryDiv.style.width =win_Width-5;
		
		editGrid.on("afteredit", function(e) {
			var field = e.field; // current field's id
			var record = e.record; // current record data
			var rowIndex = e.row; // current row number
			var colIndex = e.column; // current column number		
			var grid = e.grid; // current grid data		
			if (field == 'startTime') { 
				var startTime=record.get("startTime"); 	
				if(startTime!='')
				{
					var startArray=startTime.split(":");
					if(startArray[1]*60!=0&&startArray[1]*60!=1800)
					{
						record.set("totalHour", 0);
						record.set("startTime", '');
						return false;
					}				
				}else
				{
					record.set("totalHour", 0);
				}
				var endTime=record.get("endTime"); 
                if(endTime==null)
                {
				   endTime=''
				}				
				if(startTime!=''&&endTime!='')
				{
					var startArray=startTime.split(":");
					var endArray=endTime.split(":");	
					var startSS=startArray[0]*3600+startArray[1]*60;
					var endSS=endArray[0]*3600+endArray[1]*60;
					if(startSS>endSS)
					{
					  alert('开始时间不能大于结束时间');
					  return false;
					}
					var result=endSS-startSS;
					var hours=Number(result/3600);
					record.set("totalHour", hours);
				}			
			}
			if (field == 'endTime') { 
				var startTime=record.get("startTime"); 	
				var endTime=record.get("endTime"); 		
				if(endTime!='')
				{
					var endArray=endTime.split(":");
					if(endArray[1]*60!=0&&endArray[1]*60!=1800)
					{
						record.set("totalHour", 0);
						record.set("endTime", '');
						return false;
					}				
				}else
				{
					record.set("totalHour", 0);
				}				
				if(startTime!=''&&endTime!='')
				{
					var startArray=startTime.split(":");
					var endArray=endTime.split(":");
					var startSS=startArray[0]*3600+startArray[1]*60;
					var endSS=endArray[0]*3600+endArray[1]*60;
					if(startSS>endSS)
					{
					  alert('开始时间不能大于结束时间');
					  return false;
					}
					var result=endSS-startSS;
					var hours=Number(result/3600);
					record.set("totalHour", hours);
				}else 
				{
				   if(startTime=='')
				   {
				      alert('请输入开始时间!');
					  return false;
				   }
				   if(endTime=='')
				   {
				      alert('请输入结束时间!');
					  return false;
				   }
				}			
			}
		});			
	
	});
	
	function checkEntry(){
		var store=editGrid.getStore();
		if(store.data.length<1){
		  alert("保存失败：分录不能为空！");
		  return false;
		}
		for(var i=0;i<store.data.length;i++){
			var otType = store.getAt(i).data['otType'];
		    var row = i+1;
			var OTDate = store.getAt(i).data['OTDate'];
			var otDeal = store.getAt(i).data['otDeal'];
		   if(OTDate==null||OTDate==""||OTDate==undefined){
		     alert("保存失败！\n分录第【"+row+"】行加班日期为空！");
			 return false;
		   }
		   if(otType==null||otType==""||otType==undefined){
		     alert("保存失败！\n分录第【"+row+"】行加班类型为空！");
			 return false;
		   }
		   if(otDeal==null||otDeal==""||otDeal==undefined){
		     alert("保存失败！\n分录第【"+row+"】行加班处理方式为空！");
			 return false;
		   }
			var startTime = store.getAt(i).data['startTime'];
			var endTime = store.getAt(i).data['endTime'];
			if(!isNotEmpty(startTime))
		   {
			 alert("保存失败！\n分录第【"+row+"】行开始时间为空！");
			 return false;
		   }
			if(!isNotEmpty(endTime))
		   {
			 alert("保存失败！\n分录第【"+row+"】行结束时间为空！");
			 return false;
		   }
			var address = store.getAt(i).data['address'];
			if(!isNotEmpty(address))
		   {
			 alert("保存失败！\n分录第【"+row+"】行加班地点不能为空！");
			 return false;
		   }
			var remark = store.getAt(i).data['remark'];
			if(!isNotEmpty(remark))
		   {
			 alert("保存失败！\n分录第【"+row+"】行加班内容不能为空！");
			 return false;
		   }
		}
	    return true;
	}
	
	 function btnMySave(){
		if(checkEntry())
		{
			btnSave.fireEvent("click");
		}
	 }
	 
	 function btnMySumit(){
		if(checkEntry())
		{
			btnSubmit.fireEvent("click");
		}
	 }

	function showProcessDiagramWin()
	{	
		var bosID = encodeId(txtfid.value);
		KDWin.open('../../../../workflow/viewProcessDiagramWl.jsf?billId=' + bosID,{name:'',title:'',X:960,Y:720,scroll:'yes',resizable:'yes',Maximize:'no',Minimize:'no'});
	}	

	function isNotEmpty(valueObj)
	{
		if(valueObj==null||valueObj==""||valueObj==undefined){
		   return false;
		}else
		{
		   return true;
		}
	}	
	
	/**
	*用于转化ID 含有加好
	*/
	function encodeId(objId)
	{
		if(objId==null||objId==""){
			return objId;
		}else{
		 return objId.replace(/\+/g,'%2B');
		}
	}
